<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jstl/core"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:t="https://code.google.com/p/rad-framework/taglib"
	xmlns:tt="https://code.google.com/p/rad-framework"
	xmlns:s="http://jboss.com/products/seam/taglib" template="#{theme.layout}">
	
	<ui:param name="title" value="#{tree.master.title}" />
	
	<ui:define name="crumbs">
		<ui:include src="/themes/default/includes/crumbs.xhtml"/>
	</ui:define>
	
	<ui:define name="left">
		<h:form id="sidebarForm">
			<rich:panel style="width:192px" styleClass="rich-panel-action">
				<h:outputLink id="returnLink" value="#{contextPath}/jsf/#{tree.master.viewPath}#{tree.master.type}/Search.seam"
					styleClass="rad-framework-action-panel"
					rendered="#{!isBpmTask}">
					<h:outputText styleClass="rad-framework-action-search" value="#{messages['Search']}" />
				</h:outputLink>
				
				<h:outputLink value="#{contextPath}/MyWork"
					styleClass="rad-framework-action-panel"
					rendered="#{isBpmTask}">
					<h:outputText styleClass="rad-framework-action-search" value="#{messages['Search']}" />
				</h:outputLink>
				
				<ui:insert name="edit-view-action"/>

				<h:outputLink id="printLink"
					value="#{contextPath}/pdf/#{tree.master.viewPath}#{tree.master.type}/#{tree.master.type}.seam"
					styleClass="rad-framework-action-panel" target="_blank">
					<f:param name="id" value="#{tree.master.key}" />
					<s:conversationId />
					<h:outputText styleClass="rad-framework-action-print" value="#{messages['Print']}" />
				</h:outputLink>

				<a4j:htmlCommandLink id="cloneButton" type="submit" reRender="view"
					rendered="#{currentTree.editor.renderCreateClone}"
					styleClass="rad-framework-action-panel"
					eventsQueue="viewQ" action="#{currentTree.createClone}">
					<s:conversationId/>
					<h:outputText styleClass="rad-framework-action-clone" value="#{messages['Clone']}" />	
				</a4j:htmlCommandLink>
				
				<ui:remove>
					<h:outputLink id="exportLink"
						value="#{contextPath}/seam/resource/export/export.xml"
						styleClass="rad-framework-action-panel"
						target="_blank" rendered="#{currentTree.editor.renderExport and s:hasRole('Admin')}">
						<f:param name="component" value="#{tree.master.editor.name}"/>
						<s:conversationId/>
						<h:outputText styleClass="rad-framework-action-export" value="#{row.class.simpleName}" />	
					</h:outputLink>
				</ui:remove>
				
				<ui:insert name="actions"/>
			</rich:panel>
			<ui:insert name="sidebar-post-actions" />
			<rich:spacer width="1" height="10"/>
			<ui:insert name="workflow-panel">
			<tt:sidebar-panel label="Workflow" id="workflowActionsPanel"
				switchType="ajax" opened="true" 
				rendered="#{not empty currentTree.editor.statusActions or isBpmTask}" 
				styleClass="rad-framework-panel-bullets">
				<ui:insert name="workflow">
					<ui:repeat value="#{currentTree.editor.statusActions}" var="action"
						rendered="#{currentTaskAction == null}">
						<li>
							<a4j:htmlCommandLink type="submit" 
								value="#{action.label}"
								title="#{action.title}"
								eventsQueue="viewQ" reRender="mainTP"
								rendered="#{action.rendered}"
								disabled="#{action.disabled}"
								action="#{tree.master.editor[action.value]}">
								<s:conversationId/>
							</a4j:htmlCommandLink>
						</li>
					</ui:repeat>
				</ui:insert>
				<ui:repeat value="#{currentTaskAction.actions}" var="action"
					rendered="#{isBpmTask and !currentTask.complete}">
					<li>
						<a4j:htmlCommandLink type="submit" 
							value="#{action.label}"
							title="#{action.title}"
							eventsQueue="viewQ" reRender="mainTP"
							rendered="#{action.rendered}"
							disabled="#{action.disabled}"
							action="#{currentTaskAction[action.value]}">
							<s:conversationId/>
						</a4j:htmlCommandLink>
					</li>
				</ui:repeat>
			</tt:sidebar-panel>
			</ui:insert>
			<ui:include src="/themes/default/includes/recent.xhtml"/>
			<ui:remove>
				<ui:include src="/themes/default/includes/conversations.xhtml"/>
			</ui:remove>
		</h:form>
		<tt:sidebar-panel label="History" id="historyPanel" rendered="true" styleClass="rad-framework-panel-bullets"
			switchType="client" opened="false" >
			<ui:include src="/themes/default/includes/change-history.xhtml"/>
			<ui:include
				src="/themes/default/includes/workflow-history.xhtml"/>
		</tt:sidebar-panel>
	</ui:define>
	
	<ui:define name="center">
		<div id="view-panel">
			<h:panelGrid id="view" width="99%">
				<ui:insert name="task">
					<c:if test="#{isBpmTask}">
						<tt:toggle-panel id="taskTP" switchType="client" opened="true"
							rendered="true" label="#{messages['Task']} - #{currentTask.name}">
							<ui:include src="/themes/default/includes/task-panel.xhtml" />
						</tt:toggle-panel>
					</c:if>
				</ui:insert>
	
				
				<ui:insert name="siblings">
					<!-- todo - create button - action child only-->
					<tt:toggle-panel
						id="#{currentTree.parent.id}SibTP"
						rendered="#{currentTree.parent.renderSiblings and currentTree.editor.managed}"
						label="#{messages['Siblings']}"
						switchType="client"
						opened="false">
						
						<ui:include
							src="/themes/default/includes/folder-table.xhtml">
							<ui:param name="id" value="siblings"/>
							<ui:param name="folder" value="#{currentTree.parent}"/>
							<ui:param name="renderDelete" value="false"/>
						</ui:include>
					</tt:toggle-panel>
					<rich:spacer rendered="#{currentTree.parent.renderSiblings and currentTree.editor.managed}"
						width="1" height="5"/>
				</ui:insert>
				
				<tt:toggle-panel switchType="client" id="mainTP" opened="true"
					rendered="true" label="#{currentTree.entityTypeText}">
					<ui:insert name="main"/>
				</tt:toggle-panel>
				
				<ui:insert name="folders"/>
			</h:panelGrid>
		</div>
	</ui:define>
</ui:composition>